package com.prp.gwt.client.widgets.user.article;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.prp.gwt.client.user.article.ArticleHistoryHandler;
import com.prp.gwt.client.vo.Entity;

public class SimpleEntityItem extends VerticalPanel {

	Entity entity;

	public SimpleEntityItem(final Entity entity) {
		this.entity = entity;
		addStyleName("simple-entity-item");
		FlexTable table = new FlexTable();
		Label label = new Label("主题:");
		label.addStyleName("entity-item-label");
		table.setWidget(0, 0, label);
		HTML html = new HTML(entity.getCategoryName());
		html.addStyleName("entity-item-content");
		table.setWidget(0, 1, html);
		label = new Label("分类:");
		label.addStyleName("entity-item-label");
		table.setWidget(1, 0, label);
		html = new HTML(entity.getChildCategoryName());
		html.addStyleName("entity-item-content");
		table.setWidget(1, 1, html);
		label = new Label("名称:");
		label.addStyleName("entity-item-label");
		table.setWidget(2, 0, label);
		final HTML name = new HTML("<a>" + entity.getName() + "</a>");
		name.addClickHandler(new ClickHandler(){
			@Override
			public void onClick(ClickEvent event) {
				History.newItem(ArticleHistoryHandler.PREFIX_ENTITY+entity.getId());
			}
		});
		name.setStylePrimaryName("entity-item-content");
		table.setWidget(2, 1, name);
		add(table);
		{
			HorizontalPanel hPanel = new HorizontalPanel();
			hPanel.add(new Label("已有" + entity.getReplyNum() + "人推荐"));
			HTML recommend = new HTML("<a>我来推荐</a>");
			hPanel.add(recommend);
			recommend.addClickHandler(new ClickHandler(){
				@Override
				public void onClick(ClickEvent event) {
					History.newItem(ArticleHistoryHandler.PREFIX_ADD_RECOMMEND+entity.getId());
				}
			});
			hPanel.setSpacing(3);
			add(hPanel);
		}
		name.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				History.newItem(ArticleHistoryHandler.PREFIX_ENTITY
						+ entity.getId());
			}
		});
	}

}
